package cn.terminus.biz.customer.contractselldefypaymentoverdueinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractselldefypaymentoverdueinfo.dto.*;
import cn.terminus.data.customer.contractselldefypaymentoverdueinfo.dao.ContractSellDefyPaymentOverdueInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同付款违约(ContractSellDefyPaymentOverdueInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:18:47
 */
@Component
public class ContractSellDefyPaymentOverdueInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellDefyPaymentOverdueInfoDao contractSellDefyPaymentOverdueInfoDao;

    public Integer add(ContractSellDefyPaymentOverdueInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellDefyPaymentOverdueInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyPaymentOverdueInfoResultDto> gets(ContractSellDefyPaymentOverdueInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellDefyPaymentOverdueInfoResultDto> query(ContractSellDefyPaymentOverdueInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellDefyPaymentOverdueInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellDefyPaymentOverdueInfoResultDto> page(ContractSellDefyPaymentOverdueInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellDefyPaymentOverdueInfoResultDto> result = (Page<ContractSellDefyPaymentOverdueInfoResultDto>) contractSellDefyPaymentOverdueInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellDefyPaymentOverdueInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellDefyPaymentOverdueInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractSellDefyPaymentOverdueInfoDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("deleteWithContractId fail，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
